package com.yx.xinruitu.controller;

import com.yx.xinruitu.controller.base.BaseController;
import com.yx.xinruitu.service.IQuestionService;
import com.yx.xinruitu.util.ParameterMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/question")
public class QuestionController extends BaseController {
	
	@Autowired
	private IQuestionService questionService;
	
	/**
	 * 分页列表
	 * @return
	 */
	@RequestMapping(value="/list",method=RequestMethod.GET)
	public Object list(Model model){
		ParameterMap map=this.getParameterMap();
		if(map.containsKey("pageNo")){
			pageNo=Integer.valueOf(map.get("pageNo").toString());
		}
		map.put("is_delete",0);
		if(map.containsKey("name")){
			model.addAttribute("name",map.get("name"));
		}
		model.addAttribute("result",questionService.getQuestionListByPage(map,pageSize,pageNo));
		return "page/question/list";
	}

	/**
	 * 添加问题
	 * @return
	 */
	@RequestMapping(value="/add",method=RequestMethod.POST)
	@ResponseBody
	public Object add(){
		return questionService.add(this.getParameterMap());
	}
	
	
	/**
	 * 编辑问题
	 * @return
	 */
	@RequestMapping(value="/edit",method=RequestMethod.POST)
	@ResponseBody
	public Object edit(){
		return questionService.edit(this.getParameterMap());
	}


	/**
	 * 删除问题
	 * @return
	 */
	@RequestMapping(value="/del",method=RequestMethod.POST)
	@ResponseBody
	public Object del(){
		return questionService.del(this.getParameterMap());
	}

	/**
	 * 查找问题
	 * @return
	 */
	@RequestMapping(value="/find",method=RequestMethod.GET)
	@ResponseBody
	public Object find(){
		return questionService.find(this.getParameterMap());
	}

}
